﻿package mortal.game.view.common.guide
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import com.mui.controls.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.game.cache.*;
    import mortal.game.cache.guild.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mainUI.Navbar.*;
    import mortal.game.view.skill.*;
    import mortal.mvc.core.*;

    public class AutoGuideRedPoint2 extends Object
    {
        private var _map:Dictionary;
        public static const GuildSkillLvUp:String = "GuildSkillLvUp";
        public static const GuildGarden:String = "GuildGarden";
        public static var isSkillFull:Boolean = false;
        private static var _instance:AutoGuideRedPoint2;

        public function AutoGuideRedPoint2()
        {
            this.initMap();
            this.addEvents();
            return;
        }// end function

        private function initMap() : void
        {
            this._map = new Dictionary();
            this._map[GuildSkillLvUp] = {show:false, mType:ModuleType.Guild};
            this._map[GuildGarden] = {show:false, mType:ModuleType.Guild};
            return;
        }// end function

        private function addEvents() : void
        {
            EventUtil.addSelfEvent(EventName.NavbarButtonUIRowInited, this.initHd, true);
            Dispatcher.addEventListener(EventName.NavBarButtonPosUpdate, this.onNavBarButtonPosUpdate);
            NetDispatcher.addCmdListener(ServerCommand.GuildResourceAdd, this.onGuildResourceAdd);
            return;
        }// end function

        private function initHd(param1:Object) : void
        {
            this.onGuildResourceAdd();
            return;
        }// end function

        public function getValueByName(param1:String) : Boolean
        {
            return this._map[param1].show as Boolean;
        }// end function

        private function onNavBarRedPointShowOrHide(event:DataEvent) : void
        {
            var _loc_5:GBitmap = null;
            var _loc_2:* = event.data.mType;
            var _loc_3:* = event.data.pType;
            var _loc_4:* = GameController.navbar.view as NavbarModule;
            var _loc_6:* = _loc_4.btnBottomContainer.getChildByName(_loc_2) as GLoadedButton;
            if (this.getValueByName(_loc_3))
            {
                EffectManager.glowFilterReg(_loc_6);
            }
            else
            {
                EffectManager.glowFilterUnReg(_loc_6);
            }
            return;
        }// end function

        private function onNavBarButtonPosUpdate(event:DataEvent) : void
        {
            var _loc_2:Object = null;
            var _loc_3:String = null;
            for (_loc_3 in this._map)
            {
                
                _loc_2 = this._map[_loc_3];
                if (_loc_2.show)
                {
                    this.onNavBarRedPointShowOrHide(new DataEvent(EventName.NavBarRedPointShowOrHide, {mType:_loc_2.mType, pType:_loc_3}));
                }
            }
            return;
        }// end function

        private function onGuildResourceAdd(param1:Object = null) : void
        {
            var _loc_6:TSkill = null;
            var _loc_7:SkillInfo = null;
            var _loc_8:Boolean = false;
            var _loc_9:String = null;
            if (Cache.instance.guild.selfGuildInfo.selfHasJoinGuild == false)
            {
                return;
            }
            var _loc_2:* = Cache.instance.guild.selfGuildInfo;
            var _loc_3:* = GuildBuildingConfig.instance.getInfoByBuildingType(_loc_2.selfInfo.level, EGuildStructureType._EGuildSchool).structureLevel;
            var _loc_4:* = GuildSchoolConfig.instance.getInfoByLevel(_loc_3);
            var _loc_5:Array = ["skillLife", "skillAttack", "skillToughness", "skillCrit", "skillHit", "skillJouk", "skillDefense", "skillPenetration", "skillExpertise", "skillBlock"];
            for each (_loc_9 in _loc_5)
            {
                
                if (_loc_4[_loc_9] > 0)
                {
                    _loc_6 = SkillConfig.instance.getInfoById(_loc_4[_loc_9]);
                    _loc_7 = Cache.instance.skill.getSkillBySerialId(_loc_6.series);
                    if (_loc_2.selfInfo.contribution >= _loc_6.needGuildContribute && (_loc_7 == null || _loc_7.skillLevel < _loc_6.skillLevel))
                    {
                        _loc_8 = true;
                        break;
                    }
                }
            }
            if (_loc_8 && param1 && isSkillFull == false)
            {
                this.setValueByName(GuildSkillLvUp, true);
            }
            else if (_loc_8 == false)
            {
                this.setValueByName(GuildSkillLvUp, false, false);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideRedPointRefresh));
            return;
        }// end function

        public function setValueByName(param1:String, param2:Boolean, param3:Boolean = true) : void
        {
            this._map[param1].show = param2;
            this.onNavBarRedPointShowOrHide(new DataEvent(EventName.NavBarRedPointShowOrHide, {mType:this._map[param1].mType, pType:param1}));
            return;
        }// end function

        private function onTimeOut() : void
        {
            this.onGuildResourceAdd();
            this.register();
            return;
        }// end function

        public function register() : void
        {
            var _loc_1:* = ClockManager.instance.nowDate.time + 2 * 12 * 5 * 60 * 1000;
            ClockManager.instance.addDateCall(new Date(_loc_1), this.onTimeOut);
            return;
        }// end function

        public static function get instance() : AutoGuideRedPoint2
        {
            if (_instance == null)
            {
                _instance = new AutoGuideRedPoint2;
            }
            return _instance;
        }// end function

    }
}
